﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace TCPServer
{
    class Program
    {
        static void Main(string[] args)
        {
            IPAddress local = IPAddress.Any;
            IPEndPoint iep = new IPEndPoint(local, 13000);
            Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // 将套接字与本地终结点绑定   
            server.Bind(iep);

            //在本地13000端口号上进行监听    
            server.Listen(20);
            Console.WriteLine("等待客户机进行连接......");
            while (true)
            {
                // 得到包含客户端信息的套接字  
                Socket client = server.Accept();

                //创建消息服务线程对象  
                ClientThread newclient = new ClientThread(client);

                //把ClientThread 类的ClientService方法委托给线程  
                Thread newthread = new Thread(new ThreadStart(newclient.ClientService));

                // 启动消息服务线程  
                newthread.Start();
            }
        }
    }
}
